package com.bitoon.basketdudes.jpa;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * @author PacoFELC 2011
 */
@Entity
@Table(name = "visita", schema = "central")
@NamedQueries({
    @NamedQuery(name = "Visita.findAll"        , query = "SELECT v FROM Visita v"),
    @NamedQuery(name = "Visita.findByUsuarioId", query = "SELECT v FROM Visita v WHERE v.visitaPK.usuarioId = :usuario_id and v.visitaPK.servicioId = :servicio_id"),
    @NamedQuery(name = "Visita.findByTotal"    , query = "SELECT v FROM Visita v WHERE v.total = :total")})
public class Visita implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected VisitaPK visitaPK;
    @Column(name = "f_ultimo")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fUltimo;
    @Column(name = "total")
    private Short total;
    @JoinColumn(name = "usuario_id", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Usuario usuario;

    public Visita() {
    }

    public Visita(VisitaPK visitaPK) {
        this.visitaPK = visitaPK;
    }

    public Visita(int usuarioId, short servicioId) {
        this.visitaPK = new VisitaPK(usuarioId, servicioId);
    }

    public VisitaPK getVisitaPK() {
        return visitaPK;
    }

    public void setVisitaPK(VisitaPK visitaPK) {
        this.visitaPK = visitaPK;
    }

    public Date getFUltimo() {
        return fUltimo;
    }

    public void setFUltimo(Date fUltimo) {
        this.fUltimo = fUltimo;
    }

    public Short getTotal() {
        return total;
    }

    public void setTotal(Short total) {
        this.total = total;
    }

    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (visitaPK != null ? visitaPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Visita)) {
            return false;
        }
        Visita other = (Visita) object;
        if ((this.visitaPK == null && other.visitaPK != null) || (this.visitaPK != null && !this.visitaPK.equals(other.visitaPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.bitoon.basketdudes.jpa.Visita[visitaPK=" + visitaPK + "]";
    }

}
